package com.leather.activity.vo;

import com.leather.common.entity.Activity;
import com.leather.common.result.CodeMsg;
import com.leather.common.result.Result;
import com.leather.common.toolkits.DateKit;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

@Data
public class ActivityAddVo implements Serializable {

    private String activityTitle;

    private String activityDesc;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    private String activityAddress;

    private Integer userId;

    private Integer maxPeople;

    public Result validate(){

        if(StringUtils.isBlank(activityTitle)) {
            return Result.error(CodeMsg.EMPTY_ACTIVITY_TITLE);
        }
        if(StringUtils.isBlank(activityDesc)) {
            return Result.error(CodeMsg.EMPTY_ACTIVITY_DESC);
        }
        if(StringUtils.isBlank(activityAddress)) {
            return Result.error(CodeMsg.EMPTY_ACTIVITY_ADDRESS);
        }
        if(userId<0) {
            return Result.error(CodeMsg.ERROR_USER_ID);
        }

        return Result.success(transfer());
    }

    private Activity transfer() {
        Activity activity = new Activity();
        activity.setId(0);
        activity.setActivityTitle(activityTitle);
        activity.setActivityDesc(activityDesc);
        activity.setStartTime(startTime);
        activity.setEndTime(endTime);
        activity.setCreateTime(DateKit.now());
        activity.setMaxPeople(maxPeople);
        activity.setNowPeople(0);
        activity.setUserId(userId);
        activity.setActivityAddress(activityAddress);
        return activity;
    }

}
